/*
 * @Description: 海报
 * @Author: iamsmiling
 * @Date: 2021-06-11 08:45:23
 * @LastEditTime: 2021-06-11 10:28:53
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/domain/local/poster_share/poster_share_entity.dart';
import 'package:credit_business_circle/pages/mine/children/invitate/children/poster/poster_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:get/get.dart';

class PosterPage extends GetView<PosterController> {
  const PosterPage({Key? key}) : super(key: key);

  showShareModal(BuildContext context) {
    return showCupertinoModalPopup(
        context: context,
        builder: (BuildContext context) {
          return Material(
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
              topLeft: Radius.circular(R.dimen.sp10),
              topRight: Radius.circular(R.dimen.sp10),
            )),
            child: Container(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      for (PosterShareEntity o in controller.shareOptions)
                        Container(
                          padding: EdgeInsets.only(
                              top: R.dimen.dp50, bottom: R.dimen.dp32),
                          child: Column(
                            children: [
                              Image.asset(o.icon),
                              Container(
                                margin: EdgeInsets.only(top: R.dimen.dp5),
                                child: Text(
                                  o.label,
                                  style: TextStyle(
                                      fontSize: R.dimen.sp13,
                                      color: R.color.ff666666),
                                ),
                              )
                            ],
                          ),
                        )
                    ],
                  ),
                  Container(
                      margin: EdgeInsets.only(
                          left: R.dimen.dp18,
                          right: R.dimen.dp18,
                          bottom: R.dimen.dp18),
                      child: ElevatedButton(
                          style: ButtonStyle(
                              backgroundColor:
                                  MaterialStateProperty.all(R.color.ff00c28a)),
                          onPressed: Get.back,
                          child: Text("取消")))
                ],
              ),
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("选择海报"),
        elevation: 0,
      ),
      body: GetBuilder<PosterController>(builder: (_) {
        return Container(
          height: R.dimen.height,
          decoration: BoxDecoration(
            image: DecorationImage(
              fit: BoxFit.fill,
              image: AssetImage(R.image.posterBg),
            ),
          ),
          child: Column(
            children: [
              Transform.translate(
                offset: Offset(0, -R.dimen.dp32),
                child: Container(
                  child: CarouselSlider.builder(
                      itemCount: 3,
                      carouselController: _.controller,
                      itemBuilder: (BuildContext context, int i, int j) {
                        return Image.network(
                          "https://i.loli.net/2021/06/11/PhtEsn6oVydpW2x.png",
                          width: R.dimen.width - R.dimen.dp50 * 2,
                          height:
                              (R.dimen.width - R.dimen.dp50 * 2) * (490 / 275),
                        );
                      },
                      options: CarouselOptions(
                          viewportFraction: 0.78,
                          enlargeCenterPage: true,
                          aspectRatio: 275 / 470,
                          onPageChanged: _.onPageChanged)),
                ),
              ),
              Transform.translate(
                offset: Offset(0, -R.dimen.dp64),
                child: Container(
                  width: R.dimen.width,
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: List.generate(
                        3,
                        (index) => GestureDetector(
                              behavior: HitTestBehavior.translucent,
                              onTap: () => _.jumpTo(index),
                              child: AnimatedContainer(
                                margin: EdgeInsets.only(right: R.dimen.dp3),
                                duration: Duration(milliseconds: 500),
                                width: R.dimen.dp25,
                                height: R.dimen.dp4,
                                decoration: BoxDecoration(
                                    borderRadius:
                                        BorderRadius.circular(R.dimen.sp2),
                                    color: index == _.currentIndex
                                        ? R.color.ffffffff
                                        : R.color.ffffffff.withOpacity(.5)),
                              ),
                            )),
                  ),
                ),
              ),
              Spacer(),
              Container(
                margin: EdgeInsets.only(
                    left: R.dimen.dp63,
                    right: R.dimen.dp63,
                    bottom: R.dimen.dp27),
                child: ElevatedButton(
                  onPressed: () => showShareModal(context),
                  style: ButtonStyle(
                      textStyle: MaterialStateProperty.all(TextStyle(
                          fontSize: R.dimen.sp16,
                          fontWeight: FontWeight.w500,
                          color: R.color.ffffffff)),
                      backgroundColor:
                          MaterialStateProperty.all(R.color.ff2bb8f5)),
                  child: Text("选择并生成海报"),
                ),
              )
            ],
          ),
        );
      }),
    );
  }
}
